DESTINATIONS=
"\
-destination 'generic/platform=iOS' \
-destination 'generic/platform=iOS Simulator' \
-destination 'generic/platform=tvOS' \
-destination 'generic/platform=tvOS Simulator' \
-destination 'generic/platform=watchOS' \
-destination 'generic/platform=watchOS Simulator' \
-destination 'generic/platform=macOS' \
-destination 'generic/platform=macOS,variant=Mac Catalyst'\
"

lane :build_debug do |options|

  xcodebuild(
    scheme: "SwiftUIX",
    xcargs: "\
clean \
-configuration debug \
#{DESTINATIONS} \
-xcconfig SwiftUIX.xcconfig\
"
  )

  xcodebuild(
    scheme: "SwiftUIX",
    xcargs: "\
build \
-configuration debug \
#{DESTINATIONS} \
-xcconfig SwiftUIX.xcconfig\
"
  )

end

lane :build_release do |options|

  xcodebuild(
    scheme: "SwiftUIX",
    xcargs: "\
clean \
-configuration release \
#{DESTINATIONS} \
-xcconfig SwiftUIX.xcconfig\
"
  )

  xcodebuild(
    scheme: "SwiftUIX",
    xcargs: "\
build \
-configuration release \
#{DESTINATIONS} \
-xcconfig SwiftUIX.xcconfig\
"
  )

end

lane :generate_xcodeproj do |options|
  spm(
    command: "generate-xcodeproj",
    xcconfig: "SwiftUIX.xcconfig"
  )
end

lane :docc do
  sh("cd .. && swift package resolve;")
  sh("cd .. && xcodebuild docbuild -scheme SwiftUIX -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS';")
  $(xcrun --find docc) process-archive \
    transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/SwiftUIX.doccarchive \
    --output-path docs \
    --hosting-base-path 'SwiftUIX';
  echo "<script>window.location.href += \"/documentation/swiftuix\"</script>" > docs/index.html;
end
